<?php
/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */
class InformationComponent
{
	function InformationComponent()
	{
	}

	function action(&$params, $action)
	{
		return $this->query($params);
	}

	function query(&$params) 
	{
		$handle = get_class($this);
		$language_id = (int)$params['languageId'];

		$cache_id = $language_id;
		$json = read_cache($cache_id, $handle);
		if ($json)
		{
			if ($json == 'null') return null;
			else return json_decode($json, true);
		}
		
		$sqlQuery = 'select info_id, info_name, info_title, info_description ' .
		'from ' . TABLE_INFORMATION . ' ' .
		'where language_id=\'' . $language_id . '\' ' .
		'order by sort_order';

		$dataReturned = mysql_query($sqlQuery) or die(mysql_error());
		$i = 0;
		while($row = mysql_fetch_array($dataReturned))
		{
			$value{$handle}{$i}{'id'}= (int)$row['info_id'];
			$value{$handle}{$i}{'name'}= $row['info_name'];
			$value{$handle}{$i}{'title'}= $row['info_title'];
			$value{$handle}{$i}{'description'}= $row['info_description'];
			$i++;		}
				
		if ($value != null) $json = json_encode($value);
		write_cache($json, $cache_id, $handle);

		return $value;
	}
}
?>
